#include "../StdInc.h"
#include "SpreadOrderHelper.h"

#include <iostream>

namespace GSTrader
{
	namespace TradeStrategy
	{
		CSpreadInstrumentStrategyImpl::CSpreadInstrumentStrategyImpl(CStrategySession* pStrategySession, string strStrategyName) :
			CSpreadInstrumentStrategy(pStrategySession, strStrategyName)
		{

		}

		CSpreadInstrumentStrategyImpl::~CSpreadInstrumentStrategyImpl()
		{
		}

		void CSpreadInstrumentStrategyImpl::OnExecutionReport(CExecutionReport* pReport)
		{
			CLeg* pLeg = GetLeg(pReport->m_nInstrumentId);
			if (pLeg == NULL)
				return;

			if (pReport->IsTraded())
			{
				assert(pReport->m_pTrade);

				if (pReport->IsTradeComplete())
				{
					OnLegAllTraded(pLeg, pReport->m_pTrade);
				}
				else
				{
					OnLegPartTraded(pLeg, pReport->m_pTrade);
				}
			}
		}

		void CSpreadInstrumentStrategyImpl::OnOrderCanceled(COrder* pOrder)
		{
			CLeg* pLeg = GetLeg(pOrder->m_InstrumentId);
			if (pLeg)
			{
				OnLegCanceled(pLeg, pOrder);
			}
		}

		void CSpreadInstrumentStrategyImpl::OnNewReplaceOrder(COrder* pDeleteOrder, COrder* pNewOrder)
		{
			CLeg* pLeg = GetLeg(pDeleteOrder->m_InstrumentId);
			if (pLeg)
			{
				OnLegNewReplaceOrder(pLeg, pDeleteOrder, pNewOrder);
			}
		}

		void CSpreadInstrumentStrategyImpl::OnReplaceOrderCanceled(COrder* pOrder)
		{
			CLeg* pLeg = GetLeg(pOrder->m_InstrumentId);
			if (pLeg)
			{
				OnLegReplaceOrderCanceled(pLeg, pOrder);
			}
		}

		void CSpreadInstrumentStrategyImpl::OnReplaceSendNewOrder(COrder* pOrder)
		{
			CLeg* pLeg = GetLeg(pOrder->m_InstrumentId);
			if (pLeg)
			{
				OnLegReplaceSendNewOrder(pLeg, pOrder);
			}
		}

		void CSpreadInstrumentStrategyImpl::OnMarketData(CDepthMarketData* pMarketdata)
		{
			CLeg* pLeg = GetLeg(pMarketdata->m_nInstrumentID);
			if (pLeg)
			{
				OnLegMarketData(pLeg, pMarketdata);
			}
		}

		void CSpreadInstrumentStrategyImpl::OnOrderError(COrder* pOrder)
		{
			CLeg* pLeg = GetLeg(pOrder->m_InstrumentId);
			if (pLeg)
			{
				OnLegOrderError(pLeg, pOrder);
			}
		}

		void CSpreadInstrumentStrategyImpl::OnOrderFailed(COrder* pOrder)
		{
			CLeg* pLeg = GetLeg(pOrder->m_InstrumentId);
			if (pLeg)
			{
				OnLegOrderFailed(pLeg, pOrder);
			}
		}

		void CSpreadInstrumentStrategyImpl::OnLegMarketData(CLeg* pLeg, CDepthMarketData* pMarketdata)
		{

		}

		void CSpreadInstrumentStrategyImpl::OnLegAllTraded(CLeg* pLeg, CTrade* m_pTrade)
		{

		}

		void CSpreadInstrumentStrategyImpl::OnAllLegTraded()
		{

		}

		void CSpreadInstrumentStrategyImpl::OnLegPartTraded(CLeg* pLeg, CTrade* pTrade)
		{

		}

		void CSpreadInstrumentStrategyImpl::OnLegCanceled(CLeg* pLeg, COrder* pOrder)
		{

		}

		void CSpreadInstrumentStrategyImpl::OnLegOrderError(CLeg* pLeg, COrder* pOrder)
		{

		}

		void CSpreadInstrumentStrategyImpl::OnLegOrderFailed(CLeg* pLeg, COrder* pOrder)
		{

		}

		void CSpreadInstrumentStrategyImpl::OnLegNewReplaceOrder(CLeg* pLeg, COrder* pDeleteOrder, COrder* pNewOrder)
		{

		}

		void CSpreadInstrumentStrategyImpl::OnLegReplaceOrderCanceled(CLeg* pLeg, COrder* pOrder)
		{

		}

		void CSpreadInstrumentStrategyImpl::OnLegReplaceSendNewOrder(CLeg* pLeg, COrder* pOrder)
		{

		}
	}
}